var SqueezeBox={presets:{size:{x:600,y:450},sizeLoading:{x:200,y:150},marginInner:{x:20,y:20},marginImage:{x:50,y:75},handler:!1,target:null,closable:!0,closeBtn:!0,zIndex:65555,overlayOpacity:0.7,classWindow:"",classOverlay:"",overlayFx:{},resizeFx:{},contentFx:{},parse:!1,parseSecure:!1,ajaxOptions:{},onOpen:null,onClose:null,onUpdate:null,onResize:null,onMove:null,onShow:null,onHide:null},initialize:function(b){if(this.options)return this;this.presets=Object.merge(this.presets,b);this.options=
{};this.setOptions(this.presets).build();this.bound={window:this.resize.bind(this,!0,!0,!0),scroll:this.checkTarget.bind(this),close:this.close.bind(this),key:this.onKey.bind(this)};this.isOpen=this.isLoading=!1;return this},build:function(){this.overlay=new Element("div",{id:"sbox-overlay",styles:{display:"none",zIndex:this.options.zIndex}});this.content=new Element("div",{id:"sbox-content"});this.closeBtn=new Element("div",{id:"sbox-btn-close"});this.resizeBtn=new Element("div",{id:"sbox-btn-resize"});
this.moveArea=new Element("div",{id:"sbox-area-move"});$$(this.resizeBtn,this.moveArea).addEvents({mousedown:function(){this.addClass("active")},mouseup:function(){this.removeClass("active")}});this.win=(new Element("div",{id:"sbox-window",styles:{display:"none",zIndex:this.options.zIndex+2}})).adopt([this.closeBtn,this.resizeBtn,this.moveArea],this.content);this.fx={overlay:(new Fx.Tween(this.overlay,Object.merge({property:"opacity",onStart:Events.prototype.clearChain,duration:250,link:"cancel"},
this.options.overlayFx))).set(0),win:new Fx.Morph(this.win,Object.merge({onStart:Events.prototype.clearChain,unit:"px",duration:750,transition:Fx.Transitions.Quint.easeOut,link:"cancel",unit:"px"},this.options.resizeFx)),content:(new Fx.Tween(this.content,Object.merge({property:"zoom",duration:250,link:"cancel"},this.options.contentFx))).set(0)};$(document.body).adopt(this.overlay,this.win);this.win._this=this;this.dragger=new Drag.Move(this.win,{handle:this.moveArea,preventDefault:!0,stopPropagation:!0});
this.resizer=this.win.makeResizable({handle:this.resizeBtn,onComplete:function(b){b._this.size.x=b.getDimensions().x;b._this.size.y=b.getDimensions().y}})},assign:function(b,c){return b.addEvent("click",function(){return!SqueezeBox.fromElement(this,c)})},fromElement:function(b,c){this.initialize();this.element&&this.trash();this.element=$(b);this.setOptions(Object.merge(this.presets,c||{}));if(this.element&&this.options.parse){var d=this.element.getProperty(this.options.parse);d&&(d=JSON.decode(d,
this.options.parseSecure))&&this.setOptions(d)}this.assignOptions();this.url=(this.element?this.options.url||this.element.get("href"):b)||"";if(d=this.options.handler)return this.setContent(d,this.parsers[d].call(this,!0));var f=!1;this.parsers.some(function(b,c){var d=b.call(this);return d?(f=this.setContent(c,d),!0):!1},this);return f},assignOptions:function(){this.overlay.set("class",this.options.classOverlay);this.win.set("class",this.options.classWindow)},close:function(b){(a=this.content.getElementsByTagName("iframe")[0])&&
a.getAttribute("src").indexOf("admin.")&&window.location.reload();var c="event"==typeOf(b);c&&b.stop();if(!this.isOpen||c&&!Function.from(this.options.closable).call(this,b))return this;this.fx.overlay.start(0).chain(this.toggleOverlay.bind(this));this.win.setStyle("display","none");this.toggleListeners();this.isOpen=!1;this.trash();this.fireEvent("onClose",[this.content]);localStorage&&(localStorage.sbx=this.win.getDimensions().x,localStorage.sby=this.win.getDimensions().y);return this},trash:function(){this.element=
this.asset=null;this.options={};try{this.removeEvents().setOptions(this.presets).callChain()}catch(b){}},onError:function(){this.asset=null;this.setContent("string","Error during loading")},setContent:function(b,c){if(!this.handlers[b])return!1;this.content.className="sbox-content-"+b;this.applyTimer=this.applyContent.delay(this.fx.overlay.options.duration,this,this.handlers[b].call(this,c));if(this.overlay.retrieve("opacity"))return this;this.toggleOverlay(!0);this.fx.overlay.start(this.options.overlayOpacity);
return this.reposition()},applyContent:function(b,c){this.applyTimer=clearTimeout(this.applyTimer);this.hideContent();b?(this.isLoading&&this.toggleLoading(!1),this.fireEvent("onUpdate",[this.content],20)):this.toggleLoading(!0);this.content.empty();["string","array",!1].contains(typeOf(b))?this.content.set("html",b||""):this.content.adopt(b);this.callChain();this.isOpen?this.resize(c):(this.toggleListeners(!0),this.resize(c,!0),this.isOpen=!0,this.fireEvent("onOpen",[this.content]))},fullscreen:function(){document.sboldsize?
(this.resize(document.sboldsize,!0),document.sboldsize=null):(document.sboldsize={x:this.win.getDimensions().x,y:this.win.getDimensions().y},this.resize(document.getSize(),!0),e=this.content.getChildren()[0],e.setStyles({width:"100%",height:"100%"}))},resize:function(b,c,d){c=document.getSize();var f=document.getScroll();this.size=d?{x:Math.min(this.size.x,c.x-2*this.options.marginInner.x),y:Math.min(this.size.y,c.y-2*this.options.marginInner.y)}:Object.merge(this.isLoading?this.options.sizeLoading:
this.options.size,b);localStorage&&!d&&(Number(localStorage.sbx)&&(this.options.size.x=Math.min(Number(localStorage.sbx),c.x-2*this.options.marginInner.x)),Number(localStorage.sby)&&(this.options.size.y=Math.min(Number(localStorage.sby),c.y-2*this.options.marginInner.y)));b={width:this.size.x,height:this.size.y,left:Math.max(this.options.marginInner.x,(f.x+(c.x-this.size.x-this.options.marginInner.x)/2).toInt()),top:Math.max(this.options.marginInner.y,(f.y+(c.y-this.size.y-this.options.marginInner.y)/
2).toInt())};clearTimeout(this.showTimer||null);this.hideContent();this.win.setStyles(b).setStyle("display","");this.showTimer=this.showContent.delay(50,this);return this.reposition()},toggleListeners:function(b){b=b?"addEvent":"removeEvent";this.closeBtn[b]("click",this.bound.close);document[b]("keydown",this.bound.key)[b]("mousewheel",this.bound.scroll);window[b]("resize",this.bound.window)[b]("scroll",this.bound.window)},toggleLoading:function(b){this.isLoading=b;this.win[b?"addClass":"removeClass"]("sbox-loading");
b&&this.fireEvent("onLoading",[this.win])},toggleOverlay:function(b){this.overlay.setStyle("display",b?"":"none");$(document.body)[b?"addClass":"removeClass"]("body-overlayed")},showContent:function(){this.content.get("opacity")&&this.fireEvent("onShow",[this.win]);this.fx.content.start(1);window.disableNavigation=!0},hideContent:function(){this.content.get("opacity")||this.fireEvent("onHide",[this.win]);this.fx.content.set(0);window.disableNavigation=!1},onKey:function(b){switch(b.key){case "esc":this.close(b);
case "up":case "down":return!1}},checkTarget:function(b){try{return this.content.hasChild(b.target)}catch(c){return null}},reposition:function(){var b=document.getSize(),c=document.getScroll();this.overlay.setStyles({left:c.x+"px",top:c.y+"px",width:b.x+"px",height:b.y+"px"});this.win.setStyles({left:Math.max(10,(c.x+(b.x-this.win.offsetWidth)/2).toInt())+"px",top:Math.max(10,(c.y+(b.y-this.win.offsetHeight)/2).toInt())+"px"});return this.fireEvent("onMove",[this.overlay,this.win])},removeEvents:function(b){if(!this.$events)return this;
b?this.$events[b]&&(this.$events[b]=null):this.$events=null;return this},extend:function(b){return Object.append(this,b)},handlers:new Hash,parsers:new Hash};SqueezeBox.extend(new Events(null)).extend(new Options(null)).extend(new Chain(null));
SqueezeBox.parsers.extend({image:function(b){return b||/\.(?:jpg|png|gif)$/i.test(this.url)?this.url:!1},clone:function(b){if($(this.options.target))return $(this.options.target);if(this.element&&!this.element.parentNode)return this.element;var c=this.url.match(/#([\w-]+)$/);return c?$(c[1]):b?this.element:!1},ajax:function(b){return b||this.url&&!/^(?:javascript|#)/i.test(this.url)?this.url:!1},iframe:function(b){return b||this.url?this.url:!1},string:function(b){return!0}});
SqueezeBox.handlers.extend({image:function(b){var c,d=new Image;this.asset=null;d.onload=d.onabort=d.onerror=function(){d.onload=d.onabort=d.onerror=null;if(d.width){var b=document.getSize();b.x-=this.options.marginImage.x;b.y-=this.options.marginImage.y;c={x:d.width,y:d.height};for(var g=2;g--;)c.x>b.x?(c.y*=b.x/c.x,c.x=b.x):c.y>b.y&&(c.x*=b.y/c.y,c.y=b.y);c.x=c.x.toInt();c.y=c.y.toInt();this.asset=$(d);d=null;this.asset.setProperties({width:c.x,height:c.y});this.isOpen&&this.applyContent(this.asset,
c)}else this.onError.delay(10,this)}.bind(this);d.src=b;if(d&&d.onload&&d.complete)d.onload();return this.asset?[this.asset,c]:null},clone:function(b){return b.clone()},adopt:function(b){alert("!!"+b)},ajax:function(b){this.asset=(new Request.HTML(Object.merge({method:"get"},this.options.ajaxOptions))).addEvents({onSuccess:function(b){this.applyContent(b);this.asset=null}.bind(this),onFailure:this.onError.bind(this)});this.asset.send.delay(10,this.asset,[{url:b}])},iframe:function(b){return new Element("iframe",
Object.merge({src:b,frameBorder:0,width:"100%",height:"100%"},this.options.iframeOptions))},string:function(b){return b}});SqueezeBox.handlers.url=SqueezeBox.handlers.ajax;SqueezeBox.parsers.url=SqueezeBox.parsers.ajax;SqueezeBox.parsers.adopt=SqueezeBox.parsers.clone;
